window.onload = function () {
    innerInfo()
}
// 填写用户名
function innerInfo() {
    var banner = $('.top_banner_user')
    var banner_info = $('.top_banner_info')
    if (localStorage.getItem("username") != null) {
        // jquery ajax请求 验证token
        banner.css('display', 'none')
        banner_info.css('display', 'block')
        banner_info.append(`
                <a href="javascript:logout();">用户: ${localStorage.getItem("username")} </a>`
        );
        console.log(localStorage.getItem("username"))
    }
}

function logout() {
    localStorage.removeItem("username");
    // 清楚cookie
    delCookie('.AspNetCore.Cookies')
    alert('退出成功')
    window.location.href = "./index.html";
}
//取cookies     
function getCookie(name){
    let arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); 
    return null;
  }
  //删除cookie
  function delCookie(name){
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null)
      document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString()+";path=/";
  }